package com.google.code.multitester.myapp;

import org.easymock.EasyMock;

/**
 * @author Yuriy Sechko
 */
public class JimmyStub implements IStub
{
	private String words;

	// Field for checking whether corresponding method were called or not
	public static final EasymockStub mockForCheckingSetWordsCall = EasyMock
			.createStrictMock(EasymockStub.class);
	public static final EasymockStub mockForCheckingSetMoreWordsCall = EasyMock
			.createStrictMock(EasymockStub.class);
	public static final EasymockStub mockForCheckingTearDownCall = EasyMock
			.createStrictMock(EasymockStub.class);
	public static final EasymockStub mockForCheckingExitCall = EasyMock
			.createStrictMock(EasymockStub.class);

	/**
	 * First initialization phase. Remembers initialization word.
	 */
	public void setWords(final String word)
	{
		mockForCheckingSetWordsCall.call();
		this.words = word;
	}

	/**
	 * Second initialization phase. Remembers one more initialization word.
	 * 
	 * @param word
	 */
	public void setMoreWords(final String word)
	{
		mockForCheckingSetMoreWordsCall.call();
		this.words = this.words + word;
	}

	/**
	 * Returns specified string concatenated with initialization strings (which
	 * are set in {@see JimmyStub#setWords}) and {@see JimmyStub#setMoreWords}
	 * 
	 * @return first initialization work + second initialization word +
	 *         whatToSay
	 */
	public String say(final String whatToSay)
	{
		if (whatToSay == null)
		{
			return "NULL";
		}
		if (words == null)
		{
			return "NULL";
		}
		return whatToSay + words;
	}

	/**
	 * Dummy method for shutting-down logic.
	 */
	public static void tearDown()
	{
		mockForCheckingTearDownCall.call();
	}

	/**
	 * Dummy method for shutting-down logic
	 */
	public static void exit()
	{
		mockForCheckingExitCall.call();
	}
}
